﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;


namespace MiaProject
{
    

    class Tiro
    {
        public Vector3 pos;
        public Vector3 pos_inicial;
        public Vector3 dir;
        public float modelRot;
        public int dist_max;
        public bool status;
        public float yMin;//serve para "animacao" do tiro disparado estilo foguete (desce a uma distancia minima e segue ao destino) -> Player
        public int velTiro;

        public Tiro()
        {
            pos         = new Vector3(0, 1, 2);
	        pos_inicial = new Vector3(0, 1, 0);
            dir         = new Vector3(0, 0, 1);
            dist_max        = 2000;	    
	        status         = false;
            yMin = -500;
            velTiro = 800;

        }
        public void startTiro(Vector3 p, Vector3 dir, float modelRot,int velTiro=800)
        {
            this.pos_inicial.X = p.X;
            this.pos_inicial.Y = p.Y;
            this.pos_inicial.Z = p.Z;

            this.pos.X = p.X;
            this.pos.Y = p.Y;
            this.pos.Z = p.Z;
            
            this.dir = dir;
            this.modelRot = modelRot;

            this.status = true;

            this.velTiro = velTiro;
        }
        
        public void move(float interval)
        {
	        
            Vector3 d = new Vector3();
            d.X = pos.X - pos_inicial.X;
            d.Y = pos.Y - pos_inicial.Y;
            d.Z = pos.Z - pos_inicial.Z;

            if (d.Length() > dist_max)
	        {
		        status=false;
		        return;
	        }
            d.X = dir.X;
            d.Y = dir.Y;
            d.Z = dir.Z;
            
	        d.Normalize();
            //interval = 1.8f;
            pos.X = pos.X + d.X * (velTiro * interval);
            pos.Y = pos.Y + d.Y * (velTiro * interval);
            pos.Z = pos.Z + d.Z * (velTiro * interval);

            if (pos.Y < yMin)
                pos.Y = yMin;
            
        }

    }
}
